//app.js
//引入请求文件
var util = require('./utils/util.js');
var config = require('config.js');
let url = config.host;

let imgUrl = config.imgUrl;
// 记录-- 如果获取用户地理位置名称(无须用户授权) https://blog.csdn.net/zzwwjjdj1/article/details/79412634
// 存储用户信息
let userInfo = {};
let gobalData = {
	leaderId: '',
	name: '',
	gender: '',
	language: '',
	avatar: '',
	openid: '',
	session_key: '',
	appId: 'wx3d2e48b1fb74d85f',
	mobile: '',
	token: '',
	cid: '',
	city: '金华市'
}
App({
	onLaunch: function() {
		wx.login({
			success: (res) => {
				if (res.code) {
					let data = {
						code: res.code
					};
					util(`${url}user/getOpenid`, data) //获取openid以及session_key
						.then(function(res) {
							if (res.status == 1) {
								// 将获取到的数据存储起来
								gobalData.openid = res.content.openid;
								gobalData.session_key = res.content.session_key;
								// 默认登录
								util(`${url}user/login`, {
									openid: gobalData.openid
								}).then(res => {
									if (res.status == 1) {
										wx.setStorage({
											key: 'userInfo',
											data: res.content
										})
										gobalData = res.content.userInfo;
									}
								})

							} else {
								console.log('错误', res, 'data位', data)
							}
						});
				} else {
					console.log('获取用户登录态失败！' + res.errMsg)
				}
			}
		})
	},
	url: url,
	imgUrl: imgUrl,
	gobalData: gobalData,
	onLogins: function() {
		util(`${url}user/login`, {
			openid: gobalData.openid
		}).then(res => {
			if (res.status == 1) {
				wx.setStorage({
					key: 'userInfo',
					data: res.content
				})
				gobalData.cid = res.content.userInfo.id;
			}
		})
	},
	// 	//渐入，渐出实现 
	//   show : function(that,param,opacity){
	//     var animation = wx.createAnimation({
	//       //持续时间800ms
	//       duration: 800,
	//       timingFunction: 'ease',
	//     });
	//     //var animation = this.animation
	//     animation.opacity(opacity).step()
	//     //将param转换为key
	//     var json = '{"' + param + '":""}'
	//     json = JSON.parse(json);
	//     json[param] = animation.export()
	//     //设置动画
	//     that.setData(json)
	//   },
	// 
	//   //滑动渐入渐出
	//   slideupshow:function(that,param,px,opacity){
	//     var animation = wx.createAnimation({
	//       duration: 800,
	//       timingFunction: 'ease',
	//     });
	//     animation.translateY(px).opacity(opacity).step()
	//     //将param转换为key
	//     var json = '{"' + param + '":""}'
	//     json = JSON.parse(json);
	//     json[param] = animation.export()
	//     //设置动画
	//     that.setData(json)
	//   },
	// 
	//   //向右滑动渐入渐出
	//   sliderightshow: function (that, param, px, opacity) {
	//     var animation = wx.createAnimation({
	//       duration: 800,
	//       timingFunction: 'ease',
	//     });
	//     animation.translateX(px).opacity(opacity).step()
	//     //将param转换为key
	//     var json = '{"' + param + '":""}'
	//     json = JSON.parse(json);
	//     json[param] = animation.export()
	//     //设置动画
	//     that.setData(json)
	//   }
})
